package com.welsy.usermgt.vo
{
	import com.adobe.cairngorm.vo.IValueObject;
	import mx.collections.ArrayCollection;
	import flash.utils.describeType;
	
	[Bindable]
	public class ClassVO implements IValueObject
	{
		public var classId : int = 0;
		public var className : String = "";
		public var authorId : int = -1;
		public var creationDate : Date = new Date;
		public var durationFrom : Date = new Date; //AAAAMMGG
		public var durationTo : Date = null; //AAAAMMGG
		public var classNotes : String = "";
		public var classDescr : String = "";
		public var classUsers : ArrayCollection = new ArrayCollection;
		
		public function ClassVO() {
			classId = 0;
			className = "";
			authorId = -1;
			creationDate = new Date;
			durationFrom = new Date;
			durationTo = new Date;
			classNotes = "";
			classDescr = "";
			classUsers = new ArrayCollection;
		}
		
		/**
		 * Reads a String representation of a Date (format: YYYYMMDD)
		 * and returns the corresponding Date object
		 */
		public static function stringToDate(date : String) : Date {
			if(date == null) return null;
			if(date == "") return null; //TODO check it
			//trace(date.substr(0, 4)+" "+ String(Number(date.substr(4, 2))-1)+" "+date.substr(6, 2));
			return new Date(Number(date.substr(0, 4)), Number(date.substr(4, 2))-1, Number(date.substr(6, 2)));
		}
		
		
		/**
		 * Get the String representation for a Date (format YYYYMMDD)
		 */
		public static function dateToString(date : Date) : String {
			if(date == null) return ""; 
			
			if (date.getHours() == 0)
				date.setHours(12,0,0,0);
				
			var year : String = String(date.getUTCFullYear());
			var month : String = String(date.getUTCMonth()+1);
			var day : String = String(date.getUTCDate());
			if(month.length < 2) month = "0"+month;
			if(day.length < 2) day = "0"+day;

			return year+month+day;
		}
		
		/**
		 * Get the String representation for a Date (format DD/MM/YYYY)
		 */
		public static function dateToItalianString(date : Date): String {
			if(date == null) return ""; 
			
			if (date.getHours() == 0)
				date.setHours(12,0,0,0);
				
			var year : String = String(date.getUTCFullYear());
			var month : String = String(date.getUTCMonth()+1);
			var day : String = String(date.getUTCDate());
			if(month.length < 2) month = "0"+month;
			if(day.length < 2) day = "0"+day;
			return day+" / "+month+" / "+year;
		}
		
		public function toString() : String {
			return "Class: " + className + " (with "+ classUsers.length + " users). [ClassroomId="+classId+ "]";
		}
	}
}